package cn.rengy.auth.token;


import org.apache.commons.codec.digest.DigestUtils;

public abstract class AbstractAuthenticationToken implements HostAuthenticationToken {

	private static final long serialVersionUID = 1L;

	private String userAgent;
	
	private String clientIp;
	private String clientId;
	public AbstractAuthenticationToken() {
	}
	
	public AbstractAuthenticationToken(String userAgent, String clientIp) {
		this.userAgent = userAgent;
		this.clientIp = clientIp;
	}

	public String getUserAgent() {
		return userAgent;
	}

	public void setUserAgent(String userAgent) {
		this.userAgent = userAgent;
	}

	public String getClientIp() {
		return clientIp;
	}

	public void setClientIp(String clientIp) {
		this.clientIp = clientIp;
	}
	
	public String getHost() {
		return clientIp;
	}
	
	public String getClientId() {
		if(clientId==null) {
			clientId= DigestUtils.md5Hex(userAgent);
		}
		return clientId;
	}
}
